home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / POLYTOPE.ZIP / polytope.inc < prev    next >
Encoding:
Text File  |  1997-08-01  |  2.7 KB  |  95 lines

  1. /*
  2.  
  3.     POLYTOPE OBJECT INCLUDE FILE v1.0b - main include file
  4.     Copyright (C) 1997 Thomas Willhalm
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. */
  22.  
  23. /*
  24.     Declare polytope object from array of vectors stored as string
  25.  
  26.     Usage:
  27.     PRE:  <array>     is string with comma-separated list of vectors
  28.                   with no additional blanks
  29.     PRE:  <array>     contains at least 3 vectors
  30.     POST: <polytope>  contains convex hull of the given points
  31.     SIDE: <__cur_pos>, <__old_pos>, <__x>, <__y>, <string_vector>
  32.           <_cur_pos>, <_old_pos>, <_count>, <_end>, <_n>, <_l>, <_r>
  33.           <_array_nmb>, <_pv1>, <_pv2>, <_pv3>, <_p1>, <_p2>, <_p3>
  34.               altered
  35.     INT:  algo is in O(n^5)
  36. */
  37.  
  38. // count number of points
  39. #declare _array_nmb=0
  40. #declare _cur_pos=1
  41. #while (_cur_pos<strlen(array))
  42.     #if (!strcmp(substr(array,_cur_pos,1),"<"))
  43.                 #declare _array_nmb = _array_nmb + 1
  44.     #end
  45.     #declare _cur_pos= _cur_pos+1
  46. #end
  47.  
  48. // declare polytope
  49. #declare polytope =
  50. intersection {
  51. #declare _p1 = 1
  52. #while (_p1<_array_nmb)
  53.   #declare array_pos = _p1
  54.   #include "arrayget.inc"
  55.   #declare _pv1 = float_vector
  56.   #declare _p2 = _p1+1
  57.   #while (_p2<=_array_nmb)
  58.     #declare array_pos = _p2
  59.     #include "arrayget.inc"
  60.     #declare _pv2 = float_vector
  61.     #declare _p3 = _p2+1
  62.     #while (_p3<=_array_nmb)
  63.       #declare array_pos = _p3
  64.       #include "arrayget.inc"
  65.       #declare _pv3 = float_vector
  66.       #declare _n = vcross(_pv2-_pv1,_pv3-_pv1)
  67.       #declare _l=0
  68.       #declare _r=0
  69.       #declare array_pos = 1
  70.       #while (array_pos<=_array_nmb)
  71.         #if (array_pos!=_p1 & array_pos!=_p2 & array_pos!=_p3)
  72.           #include "arrayget.inc"
  73.           #if (vdot(float_vector-_pv1,_n)>0)
  74.             #declare _l=1
  75.           #else
  76.             #declare _r=1
  77.           #end
  78.         #end
  79.         #declare array_pos = array_pos +1
  80.       #end
  81.       #if (_l=0)
  82.         plane {_n,0 translate _pv1}
  83.       #end
  84.       #if (_r=0)
  85.         plane {-_n,0 translate _pv1}
  86.       #end
  87.       #declare _p3 = _p3 + 1
  88.     #end
  89.     #declare _p2 = _p2 + 1
  90.   #end 
  91.   #declare _p1 = _p1 + 1
  92. #end
  93. }
  94.  
  95.